<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 400px;
            margin: 100px auto;
        }

        table thead {
            background-color: skyblue;
        }

        table tbody tr {
            cursor: pointer;
        }

        .change {
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <table border="1" cellspacing="0">
        <thead>
            <tr>
                <th><input type="checkbox" id="allCheck"></th>
                <th>商品</th>
                <th>价钱</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input type="checkbox"></td>
                <td>iPhone8</td>
                <td>8000</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>iPhone8</td>
                <td>8000</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>iPhone8</td>
                <td>8000</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>iPhone8</td>
                <td>8000</td>
            </tr>
        </tbody>
    </table>

    <script>
        var tbo = document.querySelector('tbody').querySelectorAll('tr');
        for (var i = 0; i < tbo.length; i++) {
            tbo[i].onmouseover = function () {
                this.style.backgroundColor = '#ccc';
            }
            tbo[i].onmouseout = function () {
                this.style.backgroundColor = '';
            }
        }

        var allCheck = document.getElementById('allCheck');
        var checks = document.querySelector('tbody').querySelectorAll('input');
        allCheck.onclick = function() {
            console.log(this.checked);
            for(var i = 0; i < checks.length; i++) {
                checks[i].checked = this.checked;
            }
        }
        
        for(var i = 0; i < checks.length; i++) {
            checks[i].onclick = function() {
                var flag = true
                for(var i = 0; i < checks.length; i++) {
                    if(checks[i].checked == false) {
                        flag = false;
                        break;
                    }
                }
                allCheck.checked = flag;
            }
        }
    </script>
</body>

</html>